package com.kinyx.framework.constraints;

import java.lang.annotation.Annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.kinyx.framework.utils.KMatcherUtils;

abstract class RegexMatchValidator<A extends Annotation> implements ConstraintValidator<A, String> {

	@Override
	public boolean isValid(final String value, final ConstraintValidatorContext context) {
		if ((value == null) || value.trim().isEmpty()) { return true; }
		return this.validate(value, context);
	}

	protected boolean validate(final String value, final ConstraintValidatorContext context) {
		return KMatcherUtils.matches(value, this.getRegex());
	}

	protected String getRegex() { return null; }

}
